local skel = fk.CreateSkill{
  name = "lb__zhuoshi",
  tags = {Skill.Limited}
}

Fk:loadTranslationTable{
  ["lb__zhuoshi"] = "濯世",
  --[":lb__zhuoshi"] = "<b>限定技</b>，弃牌阶段开始前，你可重铸所有手牌并将此阶段改为出牌阶段。你的弃牌阶段弃牌数达到体力上限张后，此技能视为未发动过。",
  --9.21
  [":lb__zhuoshi"] = "<b>限定技</b>，弃牌阶段开始前，你可重铸所有手牌并摸体力值数张牌，然后将此阶段改为出牌阶段。你的弃牌阶段弃牌数达到体力上限张后，此技能视为未发动过。",


  ["#lb__zhuoshi"] = "濯世：你可以重铸所有手牌并摸体力值数张牌，然后将此阶段改为出牌阶段",
  ["@lb__zhuoshi"] = "濯世",

  ["$lb__zhuoshi1"] = "洞天隐月！",
  ["$lb__zhuoshi2"] = "苍龙濯世！",
}

skel:addEffect(fk.EventPhaseChanging, {
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name) and target == player and data.phase == Player.Discard
    and not player:isKongcheng()
    and player:usedSkillTimes(skel.name, Player.HistoryGame) == 0
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askToSkillInvoke(player, {
      skill_name = skel.name,
      prompt = "#lb__zhuoshi",
    })
  end,
  on_use = function(self, event, target, player, data)
    data.phase = Player.Play
    player.room:recastCard(player:getCardIds("h"), player, skel.name)
    if not player.dead then
      player:drawCards(player.hp, skel.name)
    end
  end,
})

skel:addEffect(fk.AfterCardsMove, {
  can_refresh = function (self, event, target, player, data)
    if player:hasSkill(skel.name, true) and player:usedSkillTimes(skel.name, Player.HistoryGame) > 0
    and player.phase == Player.Discard then
      for _, move in ipairs(data) do
        return move.from == player and move.skillName == "phase_discard" and move.toArea == Card.DiscardPile
        and move.moveReason == fk.ReasonDiscard
      end
    end
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    if player:hasSkill(skel.name, true) and player:usedSkillTimes(skel.name, Player.HistoryGame) > 0
    and player.phase == Player.Discard then
      for _, move in ipairs(data) do
        if move.from == player and move.skillName == "phase_discard" and move.toArea == Card.DiscardPile
        and move.moveReason == fk.ReasonDiscard then
          room:addPlayerMark(player, "@lb__zhuoshi", #move.moveInfo)
          if player:getMark("@lb__zhuoshi") >= player.maxHp then
            room:setPlayerMark(player, "@lb__zhuoshi", 0)
            player:setSkillUseHistory(skel.name)
            break
          end
        end
      end
    end
  end,
})

return skel